<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
		        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅名称">
          <a-input placeholder="请输入订阅名称" v-decorator="['fdName', validatorRules.fdName ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅说明">
          <a-textarea :rows="5" placeholder="请输入订阅说明" v-decorator="['fdExpain', {} ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否脱敏">
          <j-dict-select-tag placeholder="请输入是否脱敏"  v-decorator="['fdDes',{'initialValue':'1',rules: [{ required: true, message: '请输入是否脱敏!' }]} ]" :triggerChange="true" dictCode="autossc_release" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应用工程">
         <!-- <a-input placeholder="请输入应用工程" v-decorator="['fdProject', {} ]" />-->
          <j-dict-select-tag  v-decorator="['fdProject', validatorRules.fdProject]" placeholder="请输入应用工程" dictCode="t_sys_project,fd_projName,fd_projid" :triggerChange="true"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="开始日期">
          <a-date-picker showTime format="YYYY-MM-DD " v-decorator="[ 'fdRunDate',validatorRules.fdRunDate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="结束日期">
          <a-date-picker showTime format="YYYY-MM-DD " v-decorator="[ 'fdRunEndDate', {} ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="脱敏目标库">
      <!--    <j-dict-select-tag  v-decorator="['fdSource', {'initialValue':'1',rules: [{ required: true, message: '请输入脱敏目标库!' }]}]" placeholder="请输入脱敏目标库" dictCode="OpersscTp_targetLibrary" :triggerChange="true"/>-->
          <j-select-multiple  v-decorator="['fdSource', {'initialValue':'UAT',rules: [{ required: true, message: '请输入脱敏目标库!' }]}]"  :options="jselectMultiple.options "  disabled = "disabled" />
        </a-form-item>
     <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="申请人">
         <!-- <a-input placeholder="请输入申请人" v-decorator="['fdApplyUser', {} ]" />-->
       <j-dict-select-tag  v-decorator="['fdApplyUser', {}]"  disabled = "disabled" dictCode="sys_user,username,id," />
     </a-form-item>
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="复合人">
          <a-input placeholder="请输入复合人" v-decorator="['fdCheckUser2', {} ]" />
        </a-form-item>&ndash;&gt;
-->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <j-dict-select-tag placeholder="请输入状态"  v-decorator="['fdStatus',{'initialValue':'1',rules: [{ required: true, message: '请输入状态!' }]}]" :triggerChange="true" dictCode="operssc_status"  disabled="disabled"/>
        </a-form-item>
      <!--  <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否发布到调度平台">
          <j-dict-select-tag placeholder="请输入是否发布到调度平台"  v-decorator="['fdRelease', {'initialValue':'1',rules: [{ required: true, message: '请输入是否发布到调度平台!' }]}]" :triggerChange="true" dictCode="autossc_release" />
        </a-form-item>-->

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JSelectMultiple from '@/components/jeecg/JSelectMultiple'
  export default {
    name: 'OpersscTpModal',
    components: {
      JDate,JSelectMultiple
    },
    data() {
      return {
        jselectMultiple: {
          options: [
            { text: 'UAT', value: 'UAT' },
            { text: 'SIT', value: 'SIT' },
            { text: 'DEV', value: 'DEV' }

          ],
          value: 'UAT'
        },

        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          fdName: { rules: [{ required: true, message: '请输入订阅名称!' }] },
          fdExpain: { rules: [{ required: true, message: '请输入订阅说明!' }] },
          fdDes: {
            rules: [{ required: true, message: '请输入是否脱敏!' }]},
          fdProject: { rules: [{ required: true, message: '请输入应用工程!' }] },
          fdRunDate: { rules: [{ required: true, message: '请输入日期!' }] },
          fdRunEndDate: { rules: [{ required: true, message: '请输入结束日期!' }] },
          fdProNum: { rules: [{ required: true, message: '请输入推送频次!' }] },
          fdSource: { rules: [{ required: true, message: '请输入脱敏目标库!' }] },
          fdApplyUser: { rules: [{ required: true, message: '请输入申请人!' }] },
          fdApplyTime: { rules: [{ required: true, message: '请输入申请时间!' }] },
          fdApplyCast: { rules: [{ required: true, message: '请输入申请描述!' }] },
          fdCheckUser2: { rules: [{ required: true, message: '请输入复合人!' }] },
          fdCheckTime2: { rules: [{ required: true, message: '请输入复合时间!' }] },
          fdCheckCast2: { rules: [{ required: true, message: '请输入复合描述!' }] },
          fdStatus: { rules: [{ required: true, message: '请输入状态!' }] },
          fdRelease: { rules: [{ required: true, message: '请输入是否发布到调度平台!' }] },
          createUser: { rules: [{ required: true, message: '请输入创建人!' }] },
          updateUser: { rules: [{ required: true, message: '请输入修改人!' }] },
          isDelete: { rules: [{ required: true, message: '请输入是否删除!' }] },
        },
        url: {
          add: "/rule/opersscTp/add",
          edit: "/rule/opersscTp/edit",
          opersscTabdetailList: '/rule/opersscTp/queryOpersscTabdetailByMainId',
        }
      }
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        //初始化明细表数据
        console.log(this.model.id)
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'fdName', 'fdExpain', 'fdDes', 'fdProject', 'fdRunDate', 'fdRunEndDate', 'fdProNum', 'fdSource', 'fdApplyUser', 'fdApplyTime', 'fdApplyCast', 'fdCheckUser2', 'fdCheckTime2', 'fdCheckCast2', 'fdStatus', 'fdRelease', 'createUser', 'updateUser', 'isDelete', ))
          // 时间格式化
          this.form.setFieldsValue({ fdRunDate: this.model.fdRunDate ? moment(this.model.fdRunDate) : null })
          this.form.setFieldsValue({ fdRunEndDate: this.model.fdRunEndDate ? moment(this.model.fdRunEndDate) : null })
          this.form.setFieldsValue({ fdApplyTime: this.model.fdApplyTime ? moment(this.model.fdApplyTime) : null })
          this.form.setFieldsValue({ fdCheckTime2: this.model.fdCheckTime2 ? moment(this.model.fdCheckTime2) : null })
        });
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.fdRunDate = formData.fdRunDate?formData.fdRunDate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdRunEndDate = formData.fdRunEndDate?formData.fdRunEndDate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdApplyTime = formData.fdApplyTime?formData.fdApplyTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdCheckTime2 = formData.fdCheckTime2?formData.fdCheckTime2.format('YYYY-MM-DD HH:mm:ss'):null;
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                 that.$message.success(res.message);
                 that.$emit('ok');
               } else {
                 that.$message.warning(res.message);
               }
             }).finally(() => {
               that.confirmLoading = false;
               that.close();
             })
           }
        })
      },
      handleCancel() {
        this.close()
      }
    }
  }
</script>

<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }

  .ant-form-item-control {
    line-height: 0px;
  }

  /** 主表单行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }

  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }
</style>